package Gui.Dialogs;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import Cards.Card;
import Gui.GameFrame;
import Gui.GamePanel;
import Main.Defines;

public class ViewDealCardsDialog extends JDialog {
	private JPanel jp;
	public void buildUIContents(){
		for(Card i : Defines.CP().getDealCards()){
			JLabel mailLabel = new JLabel(i.toString());
			jp.add(mailLabel);
		}
		
		if(Defines.CP().getDealCards().size() == 0){
			JLabel noDealCards = new JLabel("Player has no deal cards");
			jp.add(noDealCards);
		}
		
		JButton ok = new JButton("OK");
		
		ok.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				dispose();
				GameFrame.getInstance().update();
			}
		});
		jp.add(ok);
	}
	public ViewDealCardsDialog(JFrame frame){
		super(frame, "View Deal Cards",true);
		jp = new JPanel();
		jp.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5))); // MAGIC NUMBERS
		jp.setLayout(new GridLayout(0,1,0,5
				
		));
		setLocationRelativeTo(GameFrame.getInstance());
		buildUIContents();
		
		add(jp);
		pack();
		// REFACTOR THIS! MAGIC NUMBER
		if(getTitle() != null){
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + 75; // MAGIC NUMBER, 75 is size of a "typical" window icon
			width = (int) Math.max(width*1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}

		setVisible(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		
		

		
	}
}
